import api from './index'
import type {
  IUserResponse,
  ICreateUserRequest,
  IUpdateUserRequest,
  IApiResponse
} from '@/types'

// 获取用户列表
export const getUsers = (params?: {
  page?: number
  limit?: number
  role?: string
  search?: string
}): Promise<IApiResponse<IUserResponse[]> & { total: number }> => {
  return api.get('/users', { params })
}

// 根据ID获取用户
export const getUserById = (id: string | number): Promise<IApiResponse<IUserResponse>> => {
  return api.get(`/users/${id}`)
}

// 创建用户
export const createUser = (data: ICreateUserRequest): Promise<IApiResponse<IUserResponse>> => {
  return api.post('/users', data)
}

// 更新用户
export const updateUser = (id: string | number, data: IUpdateUserRequest): Promise<IApiResponse<IUserResponse>> => {
  return api.put(`/users/${id}`, data)
}

// 删除用户
export const deleteUser = (id: string | number): Promise<IApiResponse> => {
  return api.delete(`/users/${id}`)
}
